﻿using CommonNet48.CommonModel;
using CommonNet48.LogUtils.Log4net;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonNet48.CommonBLL
{
    public abstract class BaseBLL
    {
        /// <summary>
        /// 日志操作对象
        /// </summary>
        public BaseBLL()
        {
            _Logger = new Log4(this.GetType());
        }

        /// <summary>
        /// 日志操作对象
        /// </summary>
        protected Log4 _Logger;

        /// <summary>
        /// 消息事件
        /// </summary>
        public Action<MyMessage<string>> OnMessage { get; set; }

        /// <summary>
        /// 抛出自定义信息1
        /// </summary>
        /// <param name="msg">信息内容</param>
        /// <param name="msgType">消息类型提示内容</param>
        /// <param name="msgColor">信息颜色</param>
        /// <param name="parameters">消息自定义参数列表(结合实际业务解析)</param>
        protected virtual void ShowMyCustomMessage(string msg, string msgType, Color msgColor, params object[] parameters)
        {
            List<object> args = new List<object> { msgType, msgColor };
            if (parameters != null && parameters.Count() > 0)
            {
                args.AddRange(parameters);
            }
            OnMessage?.Invoke(new MyMessage<string>(msg, MyMsgType.Custom1) { OtherProp = args.ToArray() });
        }

        /// <summary>
        /// 抛出错误消息
        /// </summary>
        /// <param name="msg">信息内容</param>
        /// <param name="parameters">消息自定义参数列表(结合实际业务解析)</param>
        protected virtual void ShowMyErrorMessage(string msg, params object[] parameters)
        {
            OnMessage?.Invoke(new MyMessage<string>(msg, MyMsgType.Error) { OtherProp = parameters });
        }

        /// <summary>
        /// 抛出消息(该方法比较灵活，注意每一类消息的特征，严格遵守每一类消息的格式及参数规定)
        /// </summary>
        /// <param name="msg">信息内容</param>
        /// <param name="msType">MyMsgType枚举类型</param>
        /// <param name="parameters">消息自定义参数列表(结合实际业务解析)</param>
        protected virtual void ShowMyMessage(string msg, MyMsgType msType, params object[] parameters)
        {
            OnMessage?.Invoke(new MyMessage<string>(msg, msType) { OtherProp = parameters });
        }

    }
}
